﻿
var AppUserModel = $.extend(TradeModel, {
    selRow: null, 
    editor:{
	    title: "属性",
		winid:'AppUser_EditForm',
		formid:'AppUser_EditForm_fm',
		width:720,
		height:300
	},  
    postAction: 'add',
    url: '/sysmgr/user',
    title: "用户",
    idField: "userId",
    titleField: "webName",
    toolbar: 'AppUser_Toolbar',
    datagrid: 'AppUser_Grid',
    	 selRow: null 
}); 
 
AppUserModel.reload =function() {
	fun_ReloadAppUserList();
    $('#AppUser_EditForm').dialog('close');
	  
} 
  

function fun_FindRowById(id) {
    var cRows = $('#AppUser_Grid').datagrid('getRows');
    if (id == undefined || id == '' || id == null) return null;
    for (i = 0; i < cRows.length; i++) {
        if (cRows[i][AppUserModel.idField] == id) {
            return cRows[i];
        }
    }
    return null;
}


function fun_ShowAppUserEditForm(id) {
    var paneltitle = "新增";
    if (typeof (id) == 'object') {
        AppUserModel.selRow = id;
        AppUserModel.postAction = 'update';
        paneltitle = AppUserModel.selRow['userName'];
    }
    else {
        AppUserModel.selRow = fun_FindRowById(id);
        if (AppUserModel.selRow == null) {
        	AppUserModel.selRow={};
            AppUserModel.postAction = 'add';
           AppUserModel.selRow['Depart_ID'] = $.cookie('Depart_ID');
        }
        else {
            AppUserModel.postAction = 'update';
            paneltitle = '修改：'+AppUserModel.selRow['userName'];
        }
    }
      

    $('#AppUser_EditForm_fm').form('clear' ).form('load', AppUserModel.selRow);
    $('#AppUser_EditForm').dialog({
        top: "50px",
        resizable: true,
        maximizable: true,
        width:701,
        height: 318
    })
	.dialog('open')
	.dialog('setTitle', paneltitle);
}
function fun_SaveAppUser() {
	AppUserModel.submit();
}
function fun_DelAppUser(title, id) {
	AppUserModel.del(id,title);
} 

function fun_AppUserSearchbox(value, name) {
    if (value == "" || value == null) {
        $.messager.alert('提示', '请输入关键字!', 'info');
    }
    else {
        $('#AppUser_Grid').datagrid('reload');
    }

}
function fun_ReloadAppUserList() {
    $('#AppUser_Grid').datagrid('reload');
} 
 

$(function () {
     
    $('#AppUser_Grid').datagrid({
        pageSize: 20,
        fit: true,
        singleSelect: true,
        checkbox: false,
        rownumbers: false,
        fitColumns: true,
        pagination: true, //分页控件 
        method: 'get',
        idField: AppUserModel.idField,
        treeField: AppUserModel.titleField,
        url: Onluy.basePath()+AppUserModel.url+'/list',
        loader:AppUserModel.Loader,
        toolbar: '#AppUser_Toolbar',
        columns: [
             [
            	{ title: '姓名', field: 'userName', width: 160, sortable: true, align: 'center', rowspan: 2 },
		        { field: 'sex', title: '性别', width: 50, align: 'center', formatter: formatter_Sex },
					{ field: 'webName', title: '用户名', width: 80 },
					{ field: 'phone', title: '联系电话', width: 120 },
					{ field: 'psptId', title: '证件号码', width: 120 },
					{ field: 'inDate', title: '申请日期', width: 120, formatter: formatTime },
					{ field: 'lastDotime', title: '最后次使用时间', width: 120, formatter: formatTime },
					{ field: 'email', title: '电子邮件', width: 160 },
					{ field: 'address', title: '家庭地址', width: 200 },
					{ field: 'removeTag', title: '状态', width: 100, align: 'center'  },
					{
					    field: 'opt', title: '操作', width: 100, align: 'center', rowspan: 2,
					    formatter: function (value, rec) {
					        return '<img class="btn-16" src="'+Onluy.basePath()+'/Images/icos/16/pencil.gif" onclick="fun_ShowAppUserEditForm(\'' + rec[AppUserModel.idField] + '\');" title="修改' + rec[AppUserModel.titleField] + '" />'
                                + '<img class="btn-16" src="'+Onluy.basePath()+'/Images/icos/16/delete.gif" onclick="fun_DelAppUser(\'' + rec[AppUserModel.titleField] + '\',\'' + rec[AppUserModel.idField] + '\');" title="删除' + rec[AppUserModel.titleField] + '" />';
					    }
					}
					
 
           ]
        ],
        rowStyler: function (index,row) { 
        	 if (row.removeTag  == '0') {
                 return '';
             }
             else if (row.removeTag  == '1') {
                 return 'color:gray';
             }
             else {
                 return 'color:#ff3333';
             } 
        },
        onLoadSuccess: function (data) {
            if(data.success){
       		
       	}
       	else{
       		 $.messager.alert('提示', data.msg );
       	} 
       },
        onLoadError: function (res) {
        	AppUserModel.ShowException(res);
        },
        onDblClickRow: function (rowIndex, rowData) {
            fun_ShowAppUserEditForm(rowData);
        }, 
        onBeforeLoad: function (param) { 
        	param['Depart_ID']=$.cookie('Depart_ID');
            if (!param['Depart_ID']) { 
                param['Depart_ID'] = '2'; 
            }

            param['catchKey'] = Math.random();
            param['name'] = $('#AppUser_ss').searchbox('getName');
            param['value'] = $('#AppUser_ss').searchbox('getValue');
        }
    });
    //设置分页控件  
    var p = $('#AppUser_Grid').datagrid('getPager');
    $(p).pagination({
        pageSize: 20, //每页显示的记录条数，默认为10  
        pageList: [20, 30, 50, 100], //可以设置每页记录条数的列表  
        beforePageText: '第', //页数文本框前显示的汉字  
        afterPageText: '页    共 {pages} 页',
        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
        onBeforeRefresh: function () {
            $(this).pagination('loading');
            $(this).pagination('loaded');
        }
    });

});

